/**
 * api-list
 */
var falg = true;


template.helper('fn', function (a, b) {
    if (b == 'modifyTime') {
        return fmtDate(a);
    }
});
function fmtDate(obj) {
    var date = new Date(obj);
    var y = 1900 + date.getYear();
    var m = "0" + (date.getMonth() + 1);
    var d = "0" + date.getDate();
    var h = "0" + date.getHours();
    var mm = "0" + date.getMinutes();
    var s = "0" + date.getSeconds();
    return y + "-" + m.substring(m.length - 2, m.length) + "-" + d.substring(d.length - 2, d.length) + " " + h.substring(h.length - 2, h.length) + ":" + mm.substring(mm.length - 2, mm.length) + ":" + s.substring(s.length - 2, s.length);
//return y+"-"+m.substring(m.length-2,m.length)+"-"+d.substring(d.length-2,d.length);
}

$(document).ready(function () {
    api_list(1, 10);
});

function search() {
    api_list(1, 10);
}

/*api-列表*/
function api_list(pageNum, pageSize) {
    var paramData = {
        pageNum: pageNum,
        pageSize: pageSize
    };
    var apiName = $('#apiName').val();
    var subjectId = $('#subjectId').val();
    if (apiName != "") {
        paramData.apiName = apiName;
    }

    if (subjectId != "") {
        //paramData.subjectId=subjectId; 
    }

    $.post('/back/api/list', paramData, function (data) {

        if (data.status) {
            $('#total').text(data.total);
            var html = template('test', data);
            document.getElementById("content").innerHTML = html;
            if (falg) {
                falg = false;
                $('#pageToolbar').html('');
                $('#pageToolbar').Paging({
                    pagesize: pageSize, count: data.total, toolbar: true, callback: function (page, size, count) {
                        api_list(page, size);
                    }
                });
            }
        } else {
            document.getElementById("content").innerHTML = '';
        }
    });
}


/* api-show */
function apiShow(id) {
    var params = {id: id};
    $.post('/back/api/show', params, function (data) {
        console.log(data);
    });
}